# -*-coding:utf-8-*-
# 将序列转换为二进制形式

from typing import Union, List
import  numpy as np

def BEAA(
        sequenece: str,
        order: Union[str, None] = None
) -> List:
    '''
    计算序列的二进制形式
    :param sequenece:string 序列
    :param order: Union[str,None] 默认"ACDEFGHIKLMNPQRSTVWY-"
    :return: List 返回len(sequenece)*21的维度
    '''

    if order == None:
        order = "ACDEFGHIKLMNPQRSTVWY-"
    aadict = {}
    for i, j in enumerate(order):
        aadict[j] = ['0'] * i + ['1'] + ['0'] * (len(order) - i - 1)

    encodings = []
    for i in sequenece:
        if i not in aadict:
            i='-'
        encodings = encodings + aadict[i]

    return encodings

def one_BEAA(data, windows=15):
    data = data
    length = len(data)
    data_X = np.zeros((length, (2*windows+1), 21))
    data_Y = []
    for i in range(length):
        x = data[i].split(',')
        data_Y.append(int(x[4]))
        aaindex = np.array(BEAA(x[5]))
        # print(aaindex.reshape((2*windows+1),21))
        data_X[i] = aaindex.reshape((2*windows+1),21)
    data_Y = np.array(data_Y)
    return data_X, data_Y

if __name__ == '__main__':
    f_r_train = open('hit-40/totalsum.csv')
    train_data = f_r_train.readlines()
    result = one_BEAA(train_data)
    print(result)
